package com.aaa.controller.mht;

import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
import com.aaa.controller.BaseController;
import com.aaa.entity.system.PageOrder;
import com.aaa.entity.Result;
import com.aaa.entity.mht.TestPlanMht;
import com.aaa.service.mht.TestPlanMhtService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;


/**
 * 测试计划fpa(TestPlanMht)表控制层
 *
 * @author makejava
 * @since 2022-08-30 19:20:31
 */
@RestController
@RequestMapping("planMht")
public class TestPlanMhtController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private TestPlanMhtService testPlanMhtService;


    @RequestMapping("query.do")
    public String queryAll(PageOrder pageOrder,TestPlanMht testPlanMht) {
        Page page = testPlanMhtService.queryAll(pageOrder, testPlanMht);
        JSONConfig jsonConfig = JSONConfig.create();
        jsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
        String jsonStr = JSONUtil.toJsonStr(success(page.getTotal(), page.getResult()), jsonConfig);
        return jsonStr;
    }

    @RequestMapping("delete.do")
    public Result delete(int[] ids) {
        boolean b = testPlanMhtService.delete(ids);
        if (b) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

    @RequestMapping("insert.do")
    public Result insertUser(TestPlanMht testPlanMht) {
        int insert = testPlanMhtService.insertMhtPlan(testPlanMht);
        if (insert > 0) {
            return success();
        } else {
            return fail();
        }
    }

    @RequestMapping("update.do")
    public Result updateUser(TestPlanMht testPlanMht) {
        int updateUser = testPlanMhtService.updateMhtPlan(testPlanMht);
        if (updateUser > 0) {
            return success();
        } else {
            return fail();
        }
    }

    //用户查询页面
    @RequestMapping("toShowMHTPlan.do")
    public ModelAndView toShowUser(ModelAndView modelAndView){
        modelAndView.setViewName("mht/showMhtPlan");
        return modelAndView;
    }
    @RequestMapping("repetitionName.do")
    public Result repetitionName(TestPlanMht testPlanMht){
        boolean b = testPlanMhtService.repetitionName(testPlanMht);
        if (b){
            return success("计划名称可用");
        }
        return fail("计划名称重复，不可用");
    }

}

